public class timeRequiredToBuy {
    public int TimeRequiredToBuy(int[] tickets, int k) {
        int time = 0;
        while(tickets[k] != 0){
            for(int i = 0;i < tickets.length; i ++){
                if(tickets[i] == 0){
                    continue;
                }
                else{
                    tickets[i] --;
                    if(tickets[k] == 0){
                        time ++;
                        break;
                    }
                    time ++;
                }
            }
        }
        return time;
    }
}